{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": false
   },
   "source": [
    "## 1. ERNIE 3.0 Zeus 模型简介\n",
    "\n",
    "ERNIE 3.0 Zeus 是 ERNIE 3.0 系列模型的最新升级。其除了对无标注数据和知识图谱的学习之外，还通过持续学习对百余种不同形式的任务数据学习。实现了任务知识增强，显著提升了模型的零样本/小样本学习能力。[点击此处进入体验页面](https://wenxin.baidu.com/ernie3)\n",
    "\n",
    "## 2. 模型原理介绍\n",
    "\n",
    "ERNIE 3.0 Zeus 在学习过程中使用统一范式的多任务学习，建模数据中不同粒度的语义信息。为了进一步学习特定任务的相关知识，ERNIE 3.0 Zeus 提出了层次化提示（Prompt）学习技术。在数据构造时通过层次化的 Text Prompt 库将百余种不同的任务统一组织成自然语言的形式，和海量无监督文本以及百度知识图谱联合学习。此外训练过程引入了层次化的 Soft Prompt 建模了不同任务之间的共性与特性，进一步提升了模型对于不同下游任务的建模能力。\n",
    "\n",
    "![ERNIE 3.0 Zeus.png](https://bce.bdstatic.com/doc/ai-doc/wenxin/ERNIE%203.0%20Zeus_b3f228d.png)\n",
    "\n",
    "## 3. 模型快速使用\n",
    "  \n",
    "#### 温馨提示\n",
    "\n",
    "* 每个账户每日免费请求ERNIE 3.0系列服务的上限为200条输入，免费请求额度共2000条输入。如果您有更多请求额度需求和商务合作需求，请跟我们联系：[体验申请](https://wenxin.baidu.com/wenxin/apply3)\n",
    "\n",
    "\n",
    "#### 获取API Key\n",
    "\n",
    "您可以登录大模型开放API获取您的专属获取您的专属 API Key（AK）和Secret Key（SK），点击[链接](https://wenxin.baidu.com/moduleApi/key)查看您的AK和SK。请注意保护您的密钥信息，避免泄露。您可以通过删除已泄露的密钥来保护您的账户安全。\n",
    "\n",
    "![image.png](https://bce.bdstatic.com/doc/AIDP/wenxin/image_3a02673.png)\n",
    "\n",
    "#### 步骤一：安装wenxin-api工具包"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple\n",
      "Collecting wenxin-api\n",
      "  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/0e/32/fb1e931cc0436205fb53193a4c1f9fd8aae75ba71dbd999fd55b9899428b/wenxin_api-0.1.0-py3-none-any.whl (24 kB)\n",
      "Requirement already satisfied: tqdm in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from wenxin-api) (4.64.1)\n",
      "Requirement already satisfied: requests>=2.20 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from wenxin-api) (2.24.0)\n",
      "Requirement already satisfied: certifi>=2017.4.17 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from requests>=2.20->wenxin-api) (2019.9.11)\n",
      "Requirement already satisfied: chardet<4,>=3.0.2 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from requests>=2.20->wenxin-api) (3.0.4)\n",
      "Requirement already satisfied: idna<3,>=2.5 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from requests>=2.20->wenxin-api) (2.8)\n",
      "Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from requests>=2.20->wenxin-api) (1.25.6)\n",
      "Installing collected packages: wenxin-api\n",
      "Successfully installed wenxin-api-0.1.0\n",
      "\n",
      "\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m A new release of pip available: \u001b[0m\u001b[31;49m22.1.2\u001b[0m\u001b[39;49m -> \u001b[0m\u001b[32;49m22.3.1\u001b[0m\n",
      "\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m To update, run: \u001b[0m\u001b[32;49mpip install --upgrade pip\u001b[0m\n"
     ]
    }
   ],
   "source": [
    "!pip install --upgrade wenxin-api"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": false
   },
   "source": [
    "#### 步骤二： 在python环境中使用\n",
    "（注意：建议使用python3.7及以上版本）\n",
    "\n",
    "您可以通过以下代码使用您的数据集进行模型精调（将上一步骤申请的AK、SK填入下方代码的your ak和your sk中）。\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "# -*- coding: utf-8 -*\n",
    "import wenxin_api # 可以通过\"pip install wenxin-api\"命令安装\n",
    "from wenxin_api.tasks.free_qa import FreeQA\n",
    "wenxin_api.ak = \"your ak\" #输入您的API Key\n",
    "wenxin_api.sk = \"your sk\" #输入您的Secret Key\n",
    "input_dict = {\n",
    "    \"text\": \"问题：交朋友的原则是什么？\\n回答：\",\n",
    "    \"seq_len\": 512,\n",
    "    \"topp\": 0.5,\n",
    "    \"penalty_score\": 1.2,\n",
    "    \"min_dec_len\": 2,\n",
    "    \"min_dec_penalty_text\": \"。?：！[<S>]\",\n",
    "    \"is_unidirectional\": 0,\n",
    "    \"task_prompt\": \"qa\",\n",
    "    \"mask_type\": \"paragraph\"\n",
    "}\n",
    "rst = FreeQA.create(**input_dict)\n",
    "print(rst)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": false
   },
   "source": [
    "其中常见的状态码可以参考：[状态码汇总](https://wenxin.baidu.com/wenxin/docs#Ol6th102y)\n",
    "\n",
    "## 4. 模型效果\n",
    "\n",
    "在公开数据集上零样本/小样本学习的效果\n",
    "\n",
    "![效果 1.png](https://bce.bdstatic.com/doc/ai-doc/wenxin/%E6%95%88%E6%9E%9C%201_bd6c09d.png)\n",
    "\n",
    "在小样本学习理解任务上的效果\n",
    "\n",
    "![image (29).png](https://bce.bdstatic.com/doc/ai-doc/wenxin/image%20%2829%29_69558b6.png)\n",
    "\n",
    "在小样本学习生成任务上的效果\n",
    "\n",
    "![image (30).png](https://bce.bdstatic.com/doc/ai-doc/wenxin/image%20%2830%29_6a20d06.png)\n",
    "\n",
    "## 5. 应用场景\n",
    "\n",
    "智能创作、摘要生成、问答、语义检索、情感分析、信息抽取、文本匹配、文本纠错等各类自然语言理解和生成任务。\n",
    "\n",
    "## 6. 使用方案\n",
    "\n",
    "ERNIE 3.0 Zeus 发布了业界首个开放的千亿参数的中文生成 API。供各行各业的开发者调用和开发，使用其强大的零样本和小样本学习能力。\n",
    "\n",
    "#### 通过飞桨旸谷社区在线体验\n",
    "\n",
    "通过飞桨旸谷社区[在线体验](https://wenxin.baidu.com/ernie3) ERNIE 3.0 Zeus 的文本理解和文本创作能力，您可以通过 ERNIE 3.0 Zeus Prompt 接口体验预置 prompt 技能，预置技能包括作文创作、文案创作、摘要生成、问题生成、古诗创作、对联续写、小说续写、自由问答、情感分析、信息抽取、同义改写、文本匹配、文本纠错、完型填空、Text2SQL 等十余种预置技能，也可以自定义 prompt 体验 ERNIE 3.0 Zeus 强大的零样本、小样本自然语言处理能力。同样的，通过 ERNIE3.0 Zeus 接口您可以随意输入内容，体验模型强大的续写能力。\n",
    "\n",
    "#### 通过 API 调用体验\n",
    "\n",
    "ERNIE 3.0 Zeus 提供API体验调用的入口，您也可以在飞桨旸谷社区 API 体验专区申请 AK、SK 进行接口调用体验（上述已给出API接口调用体验流程）。"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "py35-paddle1.2.0"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
